package com.gjs.management.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gjs.common.manager.response.RspBody;
import com.gjs.common.microservice.api.IResourceMicroService;
import com.gjs.common.pojo.dto.request.PageQuery;
import com.gjs.common.pojo.dto.resource.ResourceDTO;
import com.gjs.common.pojo.dto.resource.ResourceQueryDTO;
import com.gjs.common.pojo.dto.resource.TypeDTO;
import com.gjs.common.pojo.dto.response.ListPageRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "资源相关接口")
@RequiredArgsConstructor
@RequestMapping("/resource")
public class ResourceController {

    @DubboReference
    private IResourceMicroService resourceMicroService;

    @GetMapping("/get_channel_map")
    @ResponseBody
    @ApiOperation("资源分类")
    public RspBody<List<TypeDTO>> listChannels() {
        return RspBody.success(resourceMicroService.listChannels());
    }

    @GetMapping("/get_edition_map")
    @ResponseBody
    @ApiOperation("资源版本")
    public RspBody<List<TypeDTO>> listEditions() {
        return RspBody.success(resourceMicroService.listEditions());
    }

    @GetMapping("/get_period_map")
    @ResponseBody
    @ApiOperation("资源学段")
    public RspBody<List<TypeDTO>> listPeriods() {
        return RspBody.success(resourceMicroService.listPeriods());
    }

    @GetMapping("/get_stage_map")
    @ResponseBody
    @ApiOperation("资源年级")
    public RspBody<List<TypeDTO>> listStages() {
        return RspBody.success(resourceMicroService.listStages());
    }

    @GetMapping("/get_subject_map")
    @ResponseBody
    @ApiOperation("资源学科")
    public RspBody<List<TypeDTO>> listSubjects() {
        return RspBody.success(resourceMicroService.listSubjects());
    }

    @GetMapping("/get_resource_map")
    @ResponseBody
    @ApiOperation("资源链表")
    public RspBody<List<ResourceDTO>> listResources(@Validated ResourceQueryDTO resourceQueryDTO) {
        return RspBody.success(resourceMicroService.listResources(resourceQueryDTO));
    }

    @GetMapping("/list")
    @ResponseBody
    @ApiOperation("资源列表")
    public RspBody<ListPageRsp<ResourceDTO>> listResources(@Validated ResourceQueryDTO resourceQueryDTO, PageQuery pageQuery) {
        IPage<ResourceDTO> iPage = resourceMicroService.listResources(resourceQueryDTO,pageQuery);
        return RspBody.success(ListPageRsp.of(iPage));
    }
}
